#include <bits/stdc++.h>
// 2025/04/05
// tag: Prim
// Author: Forever
using namespace std;
using int64 = int64_t;

int n, m, cnt, ans, dist[5001];
bool vis[5001];

class edge {
public:
    int v, w;
    edge(int v, int w)
        : v(v)
        , w(w) { };
    edge()
        : v(0)
        , w(0) { };
    bool operator<(const edge& e) const
    {
        return w > e.w;
    }
};

vector<edge> g[5001];
priority_queue<edge> q;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
    }
    memset(dist, 0x3f, sizeof(dist));
    dist[1] = 0;
    q.emplace(1, 0);
    while (!q.empty()) {
        if (cnt == n)
            break;
        int u = q.top().v, w = q.top().w;
        q.pop();
        if (vis[u])
            continue;
        vis[u] = true;
        cnt++;
        ans += w;
        for (auto& e : g[u])
            if (dist[e.v] > e.w)
                dist[e.v] = e.w, q.emplace(e.v, e.w);
    }
    if (cnt == n)
        cout << ans << endl;
    else
        cout << "orz" << endl;
    return 0;
}